// pages/draw/allApplyUser/index.js
// var common = require("../../../public.js");
// Page({
//   data: {
//     drawId: '',
//     allApplyUserInfo: {}
//   },
//   onLoad: function (options) {
//     let that = this
//     that.setData({
//       drawId: options.drawId
//     }, _ => {
//       that.getAllApplyUserList()
//     })
//   },


// })


// pages/draw/drawRank/index.js
var common = require("../../../public.js");
Page({

  data: {
    userInfo: '',
    token: '',
    drawId: '', // 抽奖id
    rankList: [],
    listBoxHeight: 0,
    active:0,
    zeroArr:[],
    oneArr:[]
  },
  onLoad: function (options) {
    let that = this
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
          drawId: options.drawId,
        }, () => {
        //   that.getRankList()
        that.getAllApplyUserList()
        })
      }
    })
    // let query = wx.createSelectorQuery();
    // query.select('.rankBanner').boundingClientRect(rect => {
    //   let clientHeight = rect.height;
    //   console.log(clientHeight)
    //   let winHeight = wx.getSystemInfoSync().windowHeight
    //   that.setData({
    //     listBoxHeight: winHeight - clientHeight
    //   })
    // }).exec();
  },
  getAllApplyUserList() {
    let that = this
    let tempJson = {
      drawId: that.data.drawId
    }
    common.post("/storeDraw/getAllApplyUserList", tempJson, function (res) {
      if (res.status === 200) {
        that.setData({
        //   allApplyUserInfo: res.data
        rankList:res.data.userList
        },()=>{
            var zeroArr = that.data.rankList.filter((x)=>  x.isAward==1 )
     
            that.setData({
                zeroArr ,
                oneArr:[]
            },()=>{
                console.log(that.data.zeroArr,"jjhhhj")
            })
        })
      }
    })
  },
  onChange(event) {
    // wx.showToast({
    //   title: `切换到标签 ${event.detail.name}`,
    //   icon: 'none',
    // });
    this.setData({
        active:event.detail.name
    },()=>{
        if(this.data.active==0){
            var zeroArr = this.data.rankList.filter((x)=>  x.isAward==1 )
            console.log(zeroArr)  //zhongjaing
            this.setData({
                zeroArr ,
                oneArr:[]
            })
        }else{
            var oneArr = this.data.rankList.filter((x)=>  x.isAward==0 )
            console.log(oneArr)
            this.setData({
                zeroArr:[],
                oneArr
            })
        }
    })
  },
  getRankList() {
    let that = this
    let tempJson = {
      userId: that.data.userInfo.id,
      token: that.data.token,
      drawId: that.data.drawId
    }
    common.wxRequest("/storeDraw/getStoreDrawRankList", "post", tempJson, 'application/x-www-form-urlencoded', function (res) {
      console.log(res.rankList)
      that.setData({
        rankList: res.data
      },()=>{
        var zeroArr = that.data.rankList.filter((x)=>  x.isAward==1 )
     
        that.setData({
            zeroArr ,
            oneArr:[]
        },()=>{
            console.log(that.data.zeroArr,"jjhhhj")
        })
      })
    })

  }

})